package me.zhenqu.services;

import me.zhenqu.model.bo.TimeLineBo;
import me.zhenqu.model.bo.UserBo;
import me.zhenqu.model.pojo.entity.Status;
import me.zhenqu.model.pojo.entity.TimeLine;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: yibing.tan
 * Date: 11-11-16
 * Time: 上午11:42
 * To change this template use File | Settings | File Templates.
 */
public final class CommonService {
    public static void createTimeLine(Status status, UserBo bo, TimeLineBo timeLineBo) {
        List<Long> followed = bo.loadFollowedUserIds(status.getUser_id());
        if (followed == null || followed.isEmpty()) return;
        TimeLine tl = null;
        long sid = status.getStatus_id();
        long pubtime = status.getPubtime().getTime();
        for (Long user_id : followed) {
            tl = new TimeLine();
            tl.setUser_id(user_id);
            tl.setStatus_id(sid);
            tl.setUpdate_time(pubtime);
            timeLineBo.save(tl);
        }
    }

    public static void updateTimeLine(Status status, Long uid, TimeLineBo timeLineBo) {
        TimeLine tl = new TimeLine();
        tl.setUser_id(uid);
        tl.setStatus_id(status.getStatus_id());
        tl.setUpdate_time(status.getPubtime().getTime());
        timeLineBo.save(tl);
    }

    public static void deleteTimeLine(Status status, Long currentUid, TimeLineBo timeLineBo) {
        TimeLine tl = new TimeLine();
        tl.setStatus_id(status.getStatus_id());
        tl.setUser_id(currentUid);
        timeLineBo.delete(tl);
    }
}
